package o;

import android.text.TextUtils;
import com.huawei.appmarket.service.deamon.bean.DownloadHistory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public final class dsv {
    private static List<DownloadHistory> ॱ = new ArrayList();

    static {
        synchronized (dsv.class) {
            ॱ.clear();
            euc.ˊ().ॱ();
            ॱ.addAll(dsw.ˋ().ˊ());
            euc.ˊ().ˏ();
        }
    }

    private dsv() {
    }

    public static synchronized List<DownloadHistory> ˊ() {
        List arrayList;
        synchronized (dsv.class) {
            arrayList = new ArrayList(ॱ);
        }
        return arrayList;
    }

    public static void ॱ(DownloadHistory downloadHistory) {
        euc.ˊ().ॱ();
        dsw.ˋ().ॱ(downloadHistory);
        euc.ˊ().ˏ();
        ˊ(downloadHistory);
    }

    public static void ॱ(String str, int i) {
        DownloadHistory ॱ = ॱ(str);
        if (ॱ != null) {
            ॱ.ˏ(i);
            euc.ˊ().ॱ();
            dsw.ˋ().ˋ(ॱ);
            euc.ˊ().ˏ();
        }
    }

    public static void ˏ(DownloadHistory downloadHistory) {
        euc.ˊ().ॱ();
        dsw.ˋ().ˋ(downloadHistory);
        euc.ˊ().ˏ();
        ˊ(downloadHistory);
    }

    public static synchronized boolean ˏ(String str) {
        boolean z;
        synchronized (dsv.class) {
            Iterator it = ॱ.iterator();
            while (it.hasNext()) {
                DownloadHistory downloadHistory = (DownloadHistory) it.next();
                if (downloadHistory != null && downloadHistory.ˋ().equals(str)) {
                    it.remove();
                    euc.ˊ().ॱ();
                    dsw.ˋ().ॱ(str);
                    euc.ˊ().ˏ();
                    z = true;
                    break;
                }
            }
            z = false;
        }
        return z;
    }

    public static synchronized boolean ˎ(long j) {
        boolean z;
        synchronized (dsv.class) {
            Iterator it = ॱ.iterator();
            while (it.hasNext()) {
                DownloadHistory downloadHistory = (DownloadHistory) it.next();
                if (downloadHistory != null && downloadHistory.ˊ() == j) {
                    it.remove();
                    euc.ˊ().ॱ();
                    dsw.ˋ().ˊ(j);
                    euc.ˊ().ˏ();
                    z = true;
                    break;
                }
            }
            z = false;
        }
        return z;
    }

    public static synchronized DownloadHistory ॱ(String str) {
        DownloadHistory downloadHistory;
        synchronized (dsv.class) {
            for (DownloadHistory downloadHistory2 : ॱ) {
                if (downloadHistory2 != null) {
                    String ˋ = downloadHistory2.ˋ();
                    if (ˋ != null && ˋ.equals(str)) {
                        break;
                    }
                }
            }
            downloadHistory2 = null;
        }
        return downloadHistory2;
    }

    public static synchronized DownloadHistory ˋ(long j) {
        DownloadHistory downloadHistory;
        synchronized (dsv.class) {
            if (j == 0) {
                downloadHistory = null;
            } else {
                for (DownloadHistory downloadHistory2 : ॱ) {
                    if (downloadHistory2 != null && downloadHistory2.ˊ() == j) {
                        break;
                    }
                }
                downloadHistory2 = null;
            }
        }
        return downloadHistory2;
    }

    private static synchronized boolean ˊ(DownloadHistory downloadHistory) {
        boolean z;
        synchronized (dsv.class) {
            if (downloadHistory != null) {
                if (!TextUtils.isEmpty(downloadHistory.ˋ())) {
                    DownloadHistory ॱ = ॱ(downloadHistory.ˋ());
                    if (ॱ != null) {
                        ॱ.remove(ॱ);
                    }
                    ॱ.add(downloadHistory);
                    z = true;
                }
            }
            z = false;
        }
        return z;
    }
}
